package edu.szu.huhanpeng.doodlingFight.controller.mainHandler 
{
	import edu.szu.huhanpeng.doodlingFight.globalConst.GlobalConst;
	import edu.szu.huhanpeng.doodlingFight.interfaces.IChessData;
	import edu.szu.huhanpeng.doodlingFight.interfaces.IChessGroupData;
	import edu.szu.huhanpeng.doodlingFight.interfaces.ISquareData;
	import edu.szu.huhanpeng.doodlingFight.model.ChessBoardProxy;
	import edu.szu.huhanpeng.doodlingFight.model.ChessGroupProxy;
	import edu.szu.huhanpeng.doodlingFight.view.GameWindowMed;
	import edu.szu.huhanpeng.doodlingFight.view.StagePanelMed;
	import flash.utils.Dictionary;
	import org.puremvc.as3.interfaces.ICommand;
	import org.puremvc.as3.interfaces.INotification;
	import org.puremvc.as3.interfaces.INotifier;
	import org.puremvc.as3.patterns.command.AsyncCommand;
	import org.puremvc.as3.patterns.command.SimpleCommand;
	
	/**
	 * ...
	 * @author Huhanpeng
	 */
	public class HSrTryToChange extends SimpleCommand implements ICommand, INotifier 
	{
		private var _groupProxy:ChessGroupProxy;
		
		//通知名	:GlobalConst.noteName.TRY_TO_CHANGE
		//包体类型	:Vector.<IChessData>
		//包体信息	:元素为交换的两个棋子data
		override public function execute(note:INotification):void 
		{
			var body:Vector.<IChessData> =  note.getBody() as Vector.<IChessData> ;
			
			if (body == null) 
			{
				if (GlobalConst.setting.DEBUG) 
				{
					throw new Error("body类型出错");
				}
				return;
			}
			
			_groupProxy = facade.retrieveProxy( ChessGroupProxy.NAME ) as ChessGroupProxy;
			
			
			var gameWindowMed:GameWindowMed = facade.retrieveMediator( GameWindowMed.NAME ) as GameWindowMed;
			gameWindowMed.disableInteract();
			
			//成功则调换两datad的位置
			if ( _groupProxy.checkSuccess(body[0], body[1]) ) 
			{
				sendNotification( GlobalConst.noteName.EXCHANGE, body );
			}
			else
			{
				sendNotification( GlobalConst.noteName.CHANGE_FAIL, body );
			}
		}
		
	}

}